home *** CD-ROM | disk | FTP | other *** search
- Path: news.bridge.net!news
- From: David Byrden <100101.2547@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Vector of abstract classes using STL
- Date: 23 Jan 1996 18:59:26 GMT
- Organization: self-employed
- Message-ID: <4e3b6e$uee@news.bridge.net>
- References: <3103699A.79F8@ce.kth.se> <3103DF74.2C71@cs.rpi.edu>
- NNTP-Posting-Host: ppp-mia2-71.bridge.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
-
-
- >>>> > I'm new to STL and have a question about vectors.
-
- >> You must either store shape references (Shape&) or shape pointers
- >> (Shape*) in the container
-
-
- I refer you to the draft standard, section 23.1.2
-
- "The type of objects stored in these components must meet the
- requirements of CopyConstructible types (_lib.copyconstructible_), and
- the additional requirements of Assignable types."
-
- It is impossible to assign a reference (that is, to point it at another
- object). Therefore, it is impossible to have a container of references.
-
- Even a beginning C++ programmer should be aware that there are no arrays
- of references, and should therefore be suspicious of the concept of
- keeping them in a container.
-
-
- >> Or, you may add the following to your Shape header:
- >> void destroy (Shape** ptr) { delete *ptr; }
-
- Interference with the internal workings of the STL is not recommeneded. In
- particular, this technique is dangerous because the global destroy()
- function is a workaround made necessary by the lack of template member
- functions in current compilers. When these become available, the global
- destroy() function will be removed from STL implementations, and this code
- will no longer work.
-
-
-
- David Byrden
-
-
- || C++ training for professional programmers ||
- || My opinions ARE those of my employer ||
-
-
-
-